const http = require('http')

/**
 * 构造http1.0
 * @type {http.ServerResponse._storeHeader}
 */
/* const serverResponseStoreHeader = http.ServerResponse.prototype._storeHeader;
http.ServerResponse.prototype._storeHeader = function () {
    this.httpVersion = '1.0';
    arguments[0] = 'HTTP/1.0' + arguments[0].slice(8);
    serverResponseStoreHeader.apply(this, arguments);
};

http.createServer(((req, res) => {
    console.log(req.url)
    res.end('Hello , this is http 1.0 version')
})).listen( 3000, err => {
    if (err) {
        return console.log('something bad happened', err)
    }
    console.log('server is listening on 3000')
}); */


//短链接服务端
http.createServer().on("request", (req, res) => {

    console.log("接收请求")
    console.log("url:"+req.url)
    console.log("headers:"+JSON.stringify(req.headers))

    let d = [];
    req.addListener("data",chunk=>{
        d.push(chunk)
    })
    req.addListener("end", ()=>{
        console.log("接收完报文：")
        console.log(d.toString())
    })

    res.statusCode = 200
    res.end(JSON.stringify({name: 'ike'}));

}).listen(9000, "0.0.0.0");
